﻿using System.Web.Mvc;
using System.ServiceModel.Syndication;
using System.Xml;
namespace WebSiteFool.Libs
{
    public class RssActionResult : ActionResult
    {
        private SyndicationFeed _feed;
        public RssActionResult(SyndicationFeed feed)
        {
            _feed = feed;
        }
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/rss+xml";
            Rss20FeedFormatter feed = new Rss20FeedFormatter(this._feed);
            using(XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
            {
                feed.WriteTo(writer);
            }
        }
    }
}